import request from "@/utils/request.js";

// 提供调用登录接口的函数
export const teacherLoginService = (loginData) => {
  const params = new URLSearchParams();
  for (let key in loginData) {
    params.append(key, loginData[key]);
  }
  return request.post("/teacher/login", params);
};

export const getTeacherInfoService = (username) => {
  return request.get(`/teacher/findByUserName`, {
    params: { username },
  });
};

export const getTeacherPersonalInfoService = (username) => {
  return request.get(`/teacher/getTeacherPersonalInfo`, {
    params: { username },
  });
};

export const listTeacherService = (params) => {
  console.log("params:", params);
  return request.get("/teacher/page", { params: params });
};

export const addTeacherService = (newTeacher) => {
  return request.post("/teacher/add", newTeacher);
};

export const updateTeacherService = (updateTeacher) => {
  return request.put("/teacher/update", updateTeacher);
};

export const deleteTeacherService = (teacherId) => {
  return request.delete(`/teacher/delete/${teacherId}`); // 需要使用反引号才能使用嵌入式表达式
};

export const resetPasswordService = (teacherId, password) => {
  return request.put(
    "/teacher/resetPassword?teacherId=" + teacherId + "&password=" + password,
  );
};
